//
//  YSGWesternSearchListCell.swift
//  EyeVisionForPatients
//
//  Created by liuyutian on 2022/7/1.
//  Copyright © 2022 QDSG. All rights reserved.
//

import UIKit

class YSGWesternSearchListCell: UITableViewCell {

    @IBOutlet weak var SpecificationsLabel: UILabel!
    @IBOutlet weak var fromLabel: UILabel!
    @IBOutlet weak var nameLabel: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)


    }
    func configure(with model: YSGWesternSearchModel) {
        let drugSpecification = "规格:".appending(model.drugSpecification) 
        let attri = NSMutableAttributedString(string: drugSpecification, attributes: [.font: UIFont.medium(12), .foregroundColor: UIColor.textGray])
        let pattern1 = "[0-9]+.[0-9]+"
        let regex = try? NSRegularExpression(pattern: pattern1)
        let results = regex?.matches(in: drugSpecification, range: NSMakeRange(0, drugSpecification.count))
        results?.forEach({ result in
            attri.addAttribute(.foregroundColor, value: UIColor.init(hex: "#4EBCB3"), range: result.range)
        })
        self.SpecificationsLabel.attributedText = attri
        
        let nameString = NSMutableAttributedString(
            string: model.name,
            attributes: [NSAttributedString.Key.font:
                UIFont(name: "PingFangSC-Semibold", size: 14.0)!])
        nameString.addAttribute(NSAttributedString.Key.foregroundColor,value:UIColor(hex: "#474747"), range: NSRange(location: 0,length:model.name.count))
        
        nameLabel.attributedText = nameString
        
        fromLabel.text = model.manufacturer
        
        
    }
}
